package com.lite.haru.myadapter;

import java.util.ArrayList;
import java.util.List;

import com.lite.haru.R;
import com.lite.haru.entity.Menu;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class RightLVAdapter extends BaseAdapter {

	private LayoutInflater inflater;
	private List<Menu> menus;

	public RightLVAdapter(String[] mRightTitles, Context mContext) {
		super();
		menus = new ArrayList<Menu>();
		inflater = LayoutInflater.from(mContext);
		for (int i = 0; i < mRightTitles.length; i++) {
			Menu menu = new Menu(mRightTitles[i]);
			menus.add(menu);
		}

	}

	@Override
	public int getCount() {
		if (null != menus) {
			return menus.size();
		} else {
			return 0;
		}
	}

	@Override
	public Object getItem(int position) {
		return menus.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;

		if (convertView == null) {
			convertView = inflater.inflate(R.layout.item_drawer_right_list,
					null);
			viewHolder = new ViewHolder();
			viewHolder.tvMenu = (TextView) convertView
					.findViewById(R.id.right_item_name);
			convertView.setTag(viewHolder);

		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		viewHolder.tvMenu.setText(menus.get(position).getMenu());
		switch (position) {

		case 0:
			Drawable drawable_set = convertView.getResources().getDrawable(
					R.drawable.topmenu_icn_set);

			// / 这一步必须要做,否则不会显示.

			drawable_set.setBounds(0, 0, drawable_set.getMinimumWidth(),
					drawable_set.getMinimumHeight());

			viewHolder.tvMenu.setCompoundDrawables(drawable_set, null, null,
					null);
			break;
		case 1:
			Drawable drawable_exit = convertView.getResources().getDrawable(
					R.drawable.topmenu_icn_exit);

			// / 这一步必须要做,否则不会显示.

			drawable_exit.setBounds(0, 0, drawable_exit.getMinimumWidth(),
					drawable_exit.getMinimumHeight());

			viewHolder.tvMenu.setCompoundDrawables(drawable_exit, null, null,
					null);
			break;

		default:
			break;
		}
		return convertView;
	}

	class ViewHolder {
		public TextView tvMenu;
	}

}
